﻿<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
      <title>FTask&lt;T&gt; 类
 | Fantasy.Net API Reference </title>
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta name="title" content="FTask&lt;T&gt; 类
 | Fantasy.Net API Reference ">
      
      <link rel="icon" href="../favicon.ico">
      <link rel="stylesheet" href="../public/docfx.min.css">
      <link rel="stylesheet" href="../public/main.css">
      <meta name="docfx:navrel" content="../toc.html">
      <meta name="docfx:tocrel" content="toc.html">
      
      <meta name="docfx:rel" content="../">
      
      
      
  </head>

  <script type="module">
    import options from './../public/main.js'
    import { init } from './../public/docfx.min.js'
    init(options)
  </script>

  <script>
    const theme = localStorage.getItem('theme') || 'auto'
    document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
  </script>

  <body class="tex2jax_ignore" data-layout="" data-yaml-mime="ManagedReference">
    <header class="bg-body border-bottom">
      <nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
        <div class="container-xxl flex-nowrap">
          <a class="navbar-brand" href="../index.html">
            <img id="logo" class="svg" src="../logo.svg" alt="Fantasy.Net">
            Fantasy.Net
          </a>
          <button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
            <i class="bi bi-three-dots"></i>
          </button>
          <div class="collapse navbar-collapse" id="navpanel">
            <div id="navbar">
              <form class="search" role="search" id="search">
                <i class="bi bi-search"></i>
                <input class="form-control" id="search-query" type="search" disabled="" placeholder="搜索" autocomplete="off" aria-label="Search">
              </form>
            </div>
          </div>
        </div>
      </nav>
    </header>

    <main class="container-xxl">
      <div class="toc-offcanvas">
        <div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
          <div class="offcanvas-header">
            <h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
            <button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
          </div>
          <div class="offcanvas-body">
            <nav class="toc" id="toc"></nav>
          </div>
        </div>
      </div>

      <div class="content">
        <div class="actionbar">
          <button class="btn btn-lg border-0 d-md-none" style="margin-top: -.65em; margin-left: -.8em" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
            <i class="bi bi-list"></i>
          </button>

          <nav id="breadcrumb"></nav>
        </div>

        <article data-uid="Fantasy.FTask`1">



  <h1 id="Fantasy_FTask_1" data-uid="Fantasy.FTask`1" class="text-break">
    FTask&lt;T&gt; 类
  
  </h1>

  <div class="facts text-secondary">
    <dl><dt>命名空间</dt><dd><a class="xref" href="Fantasy.html">Fantasy</a></dd></dl>
  <dl><dt>程序集</dt><dd>Fantasy.Net.dll</dd></dl>
  </div>

  <div class="markdown summary"><p>表示一个轻量级的异步任务（Future Task），提供类似于 Task 的异步编程模型，但仅适用于某些简单的异步操作。</p>
</div>
  <div class="markdown conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public sealed class FTask&lt;T&gt; : ICriticalNotifyCompletion, INotifyCompletion</code></pre>
  </div>



  <h4 class="section">类型参数</h4>
  <dl class="parameters">
    <dt><code>T</code></dt>
    <dd><p>任务结果的类型。</p>
</dd>
  </dl>

  <dl class="typelist inheritance">
    <dt>继承</dt>
    <dd>
      <div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
      <div><span class="xref">FTask&lt;T&gt;</span></div>
    </dd>
  </dl>

  <dl class="typelist implements">
    <dt>实现</dt>
    <dd>
      <div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.runtime.compilerservices.icriticalnotifycompletion">ICriticalNotifyCompletion</a></div>
      <div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.runtime.compilerservices.inotifycompletion">INotifyCompletion</a></div>
    </dd>
  </dl>


  <dl class="typelist derived">
    <dt>继承成员</dt>
    <dd>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object)</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object, object)</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object, object)</a>
    </div>
    <div>
      <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a>
    </div>
  </dd></dl>

  <dl class="typelist extensionMethods">
    <dt>扩展方法</dt>
    <dd>
  <div>
      <a class="xref" href="Fantasy.Helper.JsonHelper.html#Fantasy_Helper_JsonHelper_ToJson__1___0_">JsonHelper.ToJson&lt;T&gt;(T)</a>
  </div>
  </dd></dl>





  <h2 class="section" id="constructors">构造函数
</h2>


  <a id="Fantasy_FTask_1__ctor_" data-uid="Fantasy.FTask`1.#ctor*"></a>

  <h3 id="Fantasy_FTask_1__ctor" data-uid="Fantasy.FTask`1.#ctor">
  FTask()
  
  </h3>

  <div class="markdown level1 summary"></div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public FTask()</code></pre>
  </div>













  <h2 class="section" id="properties">属性
</h2>


  <a id="Fantasy_FTask_1_IsCompleted_" data-uid="Fantasy.FTask`1.IsCompleted*"></a>

  <h3 id="Fantasy_FTask_1_IsCompleted" data-uid="Fantasy.FTask`1.IsCompleted">
  IsCompleted
  
  </h3>

  <div class="markdown level1 summary"><p>获取一个值，表示异步任务是否已经完成。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public bool IsCompleted { get; }</code></pre>
  </div>





  <h4 class="section">属性值</h4>
  <dl class="parameters">
    <dt><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></dt>
    <dd></dd>
  </dl>








  <h2 class="section" id="methods">方法
</h2>


  <a id="Fantasy_FTask_1_Coroutine_" data-uid="Fantasy.FTask`1.Coroutine*"></a>

  <h3 id="Fantasy_FTask_1_Coroutine" data-uid="Fantasy.FTask`1.Coroutine">
  Coroutine()
  
  </h3>

  <div class="markdown level1 summary"><p>将任务转换为协程进行等待。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public void Coroutine()</code></pre>
  </div>













  <a id="Fantasy_FTask_1_Create_" data-uid="Fantasy.FTask`1.Create*"></a>

  <h3 id="Fantasy_FTask_1_Create_System_Boolean_" data-uid="Fantasy.FTask`1.Create(System.Boolean)">
  Create(bool)
  
  </h3>

  <div class="markdown level1 summary"><p>创建一个新的异步任务。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static FTask&lt;T&gt; Create(bool isFromPool = true)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>isFromPool</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></dt>
    <dd><p>是否从对象池中创建。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><a class="xref" href="Fantasy.FTask-1.html">FTask</a>&lt;T&gt;</dt>
    <dd><p>新的异步任务实例。</p>
</dd>
  </dl>











  <a id="Fantasy_FTask_1_GetAwaiter_" data-uid="Fantasy.FTask`1.GetAwaiter*"></a>

  <h3 id="Fantasy_FTask_1_GetAwaiter" data-uid="Fantasy.FTask`1.GetAwaiter">
  GetAwaiter()
  
  </h3>

  <div class="markdown level1 summary"><p>获取一个等待任务完成的 awaiter。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public FTask&lt;T&gt; GetAwaiter()</code></pre>
  </div>


  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><a class="xref" href="Fantasy.FTask-1.html">FTask</a>&lt;T&gt;</dt>
    <dd><p>用于等待异步任务的 awaiter。</p>
</dd>
  </dl>











  <a id="Fantasy_FTask_1_GetResult_" data-uid="Fantasy.FTask`1.GetResult*"></a>

  <h3 id="Fantasy_FTask_1_GetResult" data-uid="Fantasy.FTask`1.GetResult">
  GetResult()
  
  </h3>

  <div class="markdown level1 summary"><p>获取异步任务的结果。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public T GetResult()</code></pre>
  </div>


  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><span class="xref">T</span></dt>
    <dd><p>异步任务的结果。</p>
</dd>
  </dl>











  <a id="Fantasy_FTask_1_OnCompleted_" data-uid="Fantasy.FTask`1.OnCompleted*"></a>

  <h3 id="Fantasy_FTask_1_OnCompleted_System_Action_" data-uid="Fantasy.FTask`1.OnCompleted(System.Action)">
  OnCompleted(Action)
  
  </h3>

  <div class="markdown level1 summary"><p>在任务未完成时，注册一个操作，以便在任务完成时执行。
如果任务已经完成，操作将立即执行。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public void OnCompleted(Action continuation)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>continuation</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.action">Action</a></dt>
    <dd><p>要注册的操作。</p>
</dd>
  </dl>












  <a id="Fantasy_FTask_1_SetException_" data-uid="Fantasy.FTask`1.SetException*"></a>

  <h3 id="Fantasy_FTask_1_SetException_System_Exception_" data-uid="Fantasy.FTask`1.SetException(System.Exception)">
  SetException(Exception)
  
  </h3>

  <div class="markdown level1 summary"><p>设置异步任务的异常结果。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public void SetException(Exception exception)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>exception</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.exception">Exception</a></dt>
    <dd><p>要关联的异常信息。</p>
</dd>
  </dl>












  <a id="Fantasy_FTask_1_SetResult_" data-uid="Fantasy.FTask`1.SetResult*"></a>

  <h3 id="Fantasy_FTask_1_SetResult__0_" data-uid="Fantasy.FTask`1.SetResult(`0)">
  SetResult(T)
  
  </h3>

  <div class="markdown level1 summary"><p>设置异步任务的成功结果。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public void SetResult(T value)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>value</code> <span class="xref">T</span></dt>
    <dd><p>异步任务的结果值。</p>
</dd>
  </dl>












  <a id="Fantasy_FTask_1_UnsafeOnCompleted_" data-uid="Fantasy.FTask`1.UnsafeOnCompleted*"></a>

  <h3 id="Fantasy_FTask_1_UnsafeOnCompleted_System_Action_" data-uid="Fantasy.FTask`1.UnsafeOnCompleted(System.Action)">
  UnsafeOnCompleted(Action)
  
  </h3>

  <div class="markdown level1 summary"><p>在任务未完成时，注册一个操作，以便在任务完成时执行。
如果任务已经完成，操作将立即执行。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public void UnsafeOnCompleted(Action continuation)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>continuation</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.action">Action</a></dt>
    <dd><p>要注册的操作。</p>
</dd>
  </dl>












  <a id="Fantasy_FTask_1_WaitAny_" data-uid="Fantasy.FTask`1.WaitAny*"></a>

  <h3 id="Fantasy_FTask_1_WaitAny_Fantasy_FTask__0____" data-uid="Fantasy.FTask`1.WaitAny(Fantasy.FTask{`0}[])">
  WaitAny(params FTask&lt;T&gt;[])
  
  </h3>

  <div class="markdown level1 summary"><p>等待任意一个任务完成的异步方法。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static FTask WaitAny(params FTask&lt;T&gt;[] tasks)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>tasks</code> <a class="xref" href="Fantasy.FTask-1.html">FTask</a>&lt;T&gt;[]</dt>
    <dd><p>要等待的任务数组。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><a class="xref" href="Fantasy.FTask.html">FTask</a></dt>
    <dd></dd>
  </dl>











  <a id="Fantasy_FTask_1_WhenAll_" data-uid="Fantasy.FTask`1.WhenAll*"></a>

  <h3 id="Fantasy_FTask_1_WhenAll_Fantasy_FTask__0____" data-uid="Fantasy.FTask`1.WhenAll(Fantasy.FTask{`0}[])">
  WhenAll(params FTask&lt;T&gt;[])
  
  </h3>

  <div class="markdown level1 summary"><p>等待所有任务完成的异步方法。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static FTask WhenAll(params FTask&lt;T&gt;[] tasks)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>tasks</code> <a class="xref" href="Fantasy.FTask-1.html">FTask</a>&lt;T&gt;[]</dt>
    <dd><p>要等待的任务数组。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><a class="xref" href="Fantasy.FTask.html">FTask</a></dt>
    <dd></dd>
  </dl>











  <a id="Fantasy_FTask_1_WhenAll_" data-uid="Fantasy.FTask`1.WhenAll*"></a>

  <h3 id="Fantasy_FTask_1_WhenAll_System_Collections_Generic_List_Fantasy_FTask__0___" data-uid="Fantasy.FTask`1.WhenAll(System.Collections.Generic.List{Fantasy.FTask{`0}})">
  WhenAll(List&lt;FTask&lt;T&gt;&gt;)
  
  </h3>

  <div class="markdown level1 summary"><p>等待所有任务完成的异步方法。</p>
</div>
  <div class="markdown level1 conceptual"></div>

  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public static FTask WhenAll(List&lt;FTask&lt;T&gt;&gt; tasks)</code></pre>
  </div>

  <h4 class="section">参数</h4>
  <dl class="parameters">
    <dt><code>tasks</code> <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1">List</a>&lt;<a class="xref" href="Fantasy.FTask-1.html">FTask</a>&lt;T&gt;&gt;</dt>
    <dd><p>要等待的任务列表。</p>
</dd>
  </dl>

  <h4 class="section">返回</h4>
  <dl class="parameters">
    <dt><a class="xref" href="Fantasy.FTask.html">FTask</a></dt>
    <dd></dd>
  </dl>












</article>


        
      </div>

      <div class="affix">
        <nav id="affix"></nav>
      </div>
    </main>

    <div class="container-xxl search-results" id="search-results"></div>

    <footer class="border-top">
      <div class="container-xxl">
        <div class="flex-fill">
          <span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>
        </div>
      </div>
    </footer>
  </body>
</html>